const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

function initQuestion(that,question_info,number){
    that.setData({
      number:number,
      question: question_info.question,
      question_types: question_info.question_types,
      items: [
        { name: 'A', value: question_info.option1 },
        { name: 'B', value: question_info.option2 },
        { name: 'C', value: question_info.option3 },
        { name: 'D', value: question_info.option4 }
      ],
      answer:question_info.answer,
      chapter:question_info.chapter,
      explain:question_info.explain,
    })
}

module.exports = {
  formatTime: formatTime,
  initQuestion: initQuestion,
}
